//
//  GaoNavigationBar.m
//  DuTe
//
//  Created by Gikki Ares on 2020/12/21.
//  Copyright © 2020 vgemv. All rights reserved.
//

#import "JsNavigationBar.h"
#import "JsButtonLiiOne.h"
#import "JsNavigationBarUiParameter.h"
#import "JsGeometryManager.h"

@interface  JsNavigationBar()<JsButtonLiiOneDelegate>
{
	JsButtonLiiOne * mgaoButtonLii_back;
	CGRect rect_backBtnFrame;
	
	UILabel * mlb_title;
	JsNavigationBarUiParameter * ui;
}

@end

@implementation JsNavigationBar

- (void)awakeFromNib {
	[super awakeFromNib];
	[self commonInit];
}

- (instancetype) initWithFrame:(CGRect)frame {
	if(self = [super initWithFrame:frame]) {
		[self commonInit];
	}
	return self;
}

- (void)commonInit {
	ui = [JsNavigationBarUiParameter sharedInstance];
	mgaoButtonLii_back = [[JsButtonLiiOne alloc] init];
	[self positionBackBtnWithLeading:0 size:CGSizeMake(35, 30)];
	mgaoButtonLii_back.delegate = self;
	[self addSubview:mgaoButtonLii_back];
	
	mlb_title = [[UILabel alloc]init];
	mlb_title.textColor = [UIColor whiteColor];
	[self  addSubview:mlb_title];
	[self positionTitleLabel];
	
	
}

- (void)positionTitleLabel {
	CGFloat x = ui.mf_titleLeading;
	CGFloat y = (ui.mf_barHeight - ui.mf_titleHeight)/2;
	CGFloat w = [UIScreen mainScreen].bounds.size.width - ui.mf_titleTrailing - ui.mf_titleLeading;
	CGFloat h = ui.mf_titleHeight;
	CGRect rc_titleLabelFrame = CGRectMake(x, y, w, h);
	mlb_title.frame = rc_titleLabelFrame;
	[self addSubview:mlb_title];
}

- (void)positionBackBtnWithLeading:(CGFloat)leading size:(CGSize)size {
	CGFloat x = leading;
	CGFloat y = (self.bounds.size.height - size.height)/2;
	CGFloat w = size.width;
	CGFloat h = size.height;
	CGRect rc_backBtnFrame = CGRectMake(x, y, w, h);
	mgaoButtonLii_back.frame = rc_backBtnFrame;
	
	
	UIImage * image = [UIImage imageNamed:@"arrow_left.png"];
	[mgaoButtonLii_back setImage:image];
	JsButtonLiiVm * vm = [mgaoButtonLii_back vm];
	CGRect rect = [JsGeometryManager rectWithInsets:UIEdgeInsetsMake(2, 10, 2, 10) containerSize:mgaoButtonLii_back.frame.size];
	vm.foregroundImageViewFrame = rect;
	[mgaoButtonLii_back setupUi];
	
}

# pragma mark 2 Interface
- (void)setTitle:(NSString *)title {
	mlb_title.text = title;
}


# pragma mark Delegate
-(void)jsButtonLiiOneClicked:(JsButtonLiiOne *)button {
	if(_delegate &&[_delegate respondsToSelector:@selector(jsNavigationBarClickBack:)]) {
		[_delegate jsNavigationBarClickBack:self];
	}
}

@end
